<template>
  <div style="text-align: center;width: 70%">
       <el-form ref="form" :model="form" label-width="80px" >
         <el-form-item label="手机号">
           <el-input placeholder="请输入手机号" v-model="form.tel"></el-input>
         </el-form-item>
         <el-form-item label="验证码">
           <el-input placeholder="请输入内容" v-model="form.code" >
             <el-button slot="append"  @click="getMessageCode" :disabled="isDisabled">{{buttonName}}</el-button>
           </el-input>
         </el-form-item>
         <el-form-item>
           <el-button @click="toNext" type="primary"  :disabled="nextDisable">下一步</el-button>
         </el-form-item>
       </el-form>
     </div>
</template>

<script>
    export default {
        name: "test-tel",
        data(){
          return{
            form:{
              tel:"",
              code:""
            },
            buttonName: "获取验证码",
            isDisabled: false,
            nextDisable:false,
            time: 60
          }
        },

      methods:{
          toNext(){

            //console.log("tel"+this.$data.form.tel+"code"+this.form.code)
            //console.log("***"+this.$gloableData.serverPath+"user/userReg/identical?code"+this.form.code)
            this.$axios.post(this.$gloableData.serverPath+"user/userReg/identical?code="+this.form.code).then(res=>{
              console.log(res.data)
                  if (res.data==true){
                      this.$store.state.tel=this.form.tel;
                      this.nextDisable=false;
                    this.$emit("TT");
                  }else {
                    this.nextDisable=true;
                    alert("信息不匹配,请核对后重新输入")
                  }
            })
          },
          getMessageCode(){
            if (this.form.tel==""){
              //console.log(this.form.tel)
              alert("请输入手机号")
              this.isDisabled=true
              window.location.reload()
            }else {
              let me = this;
              me.isDisabled = true;
              let interval = window.setInterval(function() {
                me.buttonName = '（' + me.time + '秒）后重新发送';
                --me.time;
                if(me.time < 0) {
                  me.buttonName = "重新发送";
                  me.time = 20;
                  me.isDisabled = false;
                  window.clearInterval(interval);
                }
              }, 2000);
          }
            this.$axios.post(this.$gloableData.serverPath+"auth/telcode/sg?phone="+this.$data.form.tel).then(res=>{
              console.log(res.data)
            })
          }
        }
    }
</script>

<style scoped>

</style>
